package com.xintonghua.bussiness.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.xintonghua.base.adapter.BaseAdapter;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.EvaluteBean;
import com.xintonghua.bussiness.util.GlideUtils;
import com.xintonghua.bussiness.util.MyUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/2/28.
 * 包名：com.xintonghua.bussiness.adapter
 */

public class EvaluteAdapter extends BaseAdapter<EvaluteBean, EvaluteAdapter.EvaluteViewHolder> {


    public EvaluteAdapter(Activity mActivity, List<EvaluteBean> list) {
        super(mActivity, list);
    }

    @Override
    public EvaluteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_evalute, parent, false);
        return new EvaluteViewHolder(view);
    }


    @Override
    public void onBindViewHolder(EvaluteViewHolder holder, int position) {
        EvaluteBean bean = list.get(position);
        GlideUtils.loadCricle(mActivity, holder.ivEvaluteHead, bean.getHead_img());
        holder.tvEvaluteUsername.setText(bean.getNickname());
        holder.ratbarScore.setRating(bean.getStar());
        holder.tvCreateTime.setText(bean.getCreate_time());
        holder.tvEvaluteContent.setText(bean.getContent());
        EvaluteImageAdapter adapter = new EvaluteImageAdapter(MyUtils.getListStringSplitValue(bean.getImgs()), mActivity);
        holder.gvEvalutePic.setAdapter(adapter);
        holder.tvEvaluteStore.setText(bean.getShop_name());
        holder.tvConsumeTime.setText(TextUtils.isEmpty(bean.getConsumption_time())?"":"消费时间：" + bean.getConsumption_time());
    }

    class EvaluteViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_evalute_head)
        ImageView ivEvaluteHead;
        @BindView(R.id.tv_evalute_username)
        TextView tvEvaluteUsername;
        @BindView(R.id.ratbar_score)
        RatingBar ratbarScore;
        @BindView(R.id.tv_evalute_content)
        TextView tvEvaluteContent;
        @BindView(R.id.gv_evalute_pic)
        GridView gvEvalutePic;
        @BindView(R.id.tv_evalute_store)
        TextView tvEvaluteStore;
        @BindView(R.id.tv_consume_time)
        TextView tvConsumeTime;
        @BindView(R.id.tv_create_time)
        TextView tvCreateTime;

        public EvaluteViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
